<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="com.webshop.domain.Items" %>
<%@ page import="com.webshop.Dao.PageDao" %>
<%@ page import="com.webshop.Dao.ProductDao" %><%--
  Created by IntelliJ IDEA.
  User: jxdck662
  Date: 2019/8/13
  Time: 13:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% response.setCharacterEncoding("UTF-8");%>
<% Items items = ProductDao.getItem(Integer.parseInt(request.getParameter("id")));
    if(items == null){
        response.sendRedirect("noitem.jsp");
        return;
    }
    else
        pageContext.setAttribute("items",items);
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <title>web商城</title>
    <style type="text/css">
        .col div{
            margin: 20px;
        }
        #row .col{
            padding-top: 12px;
            padding-bottom: 12px;
            border: 1px solid #000000;
        }
    </style>
</head>
<body>
<!-- header -->
<div class="container-fluid" >
    <div class="row">
        <div class="col-4"><img src="img/logo2.png" ></div>
        <div class="col-5"><img src="img/header.jpg" ></div>
        <div class="col">
            <c:if test="${sessionScope.user == null}">
                <div class="btn-group float-right" role="group" style="margin-top: 11px;">
                    <a href="LoginServlet"><button type="button" class="btn btn-outline-success">登录</button></a>
                    <a href="register.jsp"><button type="button" class="btn btn-outline-info">注册</button></a>
                    <a href="cart.jsp"><button type="button" class="btn btn-outline-secondary">购物车</button> </a>
                </div>
            </c:if>
            <c:if test="${sessionScope.user != null}">
                <div class="btn-group float-right" role="group" style="margin-top: 11px;">
                    <a href="GetUserServlet"><button type="button" class="btn btn-outline-success">${sessionScope.user.name}</button></a>
                    <a href="LogoutServlet"><button type="button" class="btn btn-outline-info">退出</button></a>
                    <a href="cart.jsp"><button type="button" class="btn btn-outline-secondary">购物车</button> </a>
                    <a href="./GetBusServlet"><button type="button" class="btn btn-outline-danger">我的订单</button> </a>
                </div>
            </c:if>
        </div>
    </div>
</div>
<!-- nav -->
<div class="container-fluid border border-primary" >
    <nav class="navbar navbar-dark bg-dark">
        <nav class="nav nav-pills">
            <c:forEach var="i" begin="0" end="${Items.size}">
                <a class="nav-link text-light" href="items.jsp?pclass=${i}&n=1">${Items.allclass[i]}</a>
            </c:forEach>
            <a class="nav-link text-light" href="index.jsp">首页</a>
        </nav>
        <form class="form-inline my-2 my-lg-0 " action="Search" method="post">
            <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search" name="search">
            <button class="btn btn-outline-light my-2 my-sm-0" type="submit">Search</button>
        </form>
    </nav>
</div>
<!-- bread -->
<div></div>
<div class="container-fluid" id="bread" >
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="index.jsp">Home</a></li>
            <li class="breadcrumb-item"><a href="GetPageServlet?id=<%= Items.allclass.indexOf(items.getPclass())%>">${items.pclass}</a></li>
            <li class="breadcrumb-item active" aria-current="page">${items.pname}</li>
        </ol>
    </nav>
</div>
<!-- product img & price -->
<div class="container border border-dark text-light text-lg-left" style="background-color: gray; margin-top: 10px;">商品信息</div>
<div class="container">
    <div class="row">
        <div class="col">
            <img class="medium" src="${items.pimgsrc}" style="width: 400px; height: 350px;">
        </div>
        <div class="col" >
            <div>商品名：${items.pname}</div>
            <div>商品编号:${items.id}</div>
            <div>XX价:${items.pprice} 原价：999</div>
            <div>促销：否</div>
            <div style="width: 330px; background-color: burlywood; padding: 10px;">
                <form action="CartServlet" method="get">
                    <input type="hidden" name="method" id="method" value="add" />
                    <input type="hidden" name="product" id="product" value="${items.id}" />
                    购买数量：<input type="text" id="num" name="num"/>
                    <button type="submit" class="btn btn-dark btn-sm">添加购物车</button>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 介绍 -->
<div class="container border border-dark text-light text-lg-left" style="background-color: gray; margin-top: 10px;">
    商品介绍
</div>
<div class="container">
    <p>${items.pinfo}</p>
</div>
<!-- 参数 -->
<div class="container">
    <div class="row" id="row">
        <div class="col">商品参数</div>
        <c:if test="${items.attr eq null}">
            <div class="w-100"></div>
            <div class="col" style="text-align: center">暂无</div>
        </c:if>
        <c:if test="${items.attr ne null}">
            <%
                String[] attrs = (String[]) items.getAttr().split("#");
                String[] attrvs = (String[])items.getAttrv().split("#");
                pageContext.setAttribute("attrs",attrs);
                pageContext.setAttribute("attrvs",attrvs);
            %>
            <c:forEach var="i" begin="0" end="${fn:length(attrs)-1}">
                <div class="w-100"></div>
                <div class="col">${attrs[i]}</div>
                <div class="col">${attrvs[i]}</div>
            </c:forEach>
        </c:if>
    </div>
</div>
<!-- footer -->
<div class="container-fluid" >
    <nav class="nav justify-content-center">
        <a class="nav-link">关于我们</a>
        <a class="nav-link">联系我们</a>
        <a class="nav-link">招贤纳士</a>
        <a class="nav-link">法律声明</a>
        <a class="nav-link">友情链接</a>
        <a class="nav-link" target="_blank">支付方式</a>
        <a class="nav-link" target="_blank">配送方式</a>
        <a class="nav-link">服务声明</a>
        <a class="nav-link">广告声明</a>
    </nav>
</div>
<div style="text-align: center;margin-top: 5px;margin-bottom:20px;">
    Copyright &copy; 2005-2016 传智商城 版权所有
</div>
<script src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript">

</script>
</body>
</html>

